/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bpmlab.shift.bean;

import bpmlab.shift.dao.DAOException;
import bpmlab.shift.dao.DAOFactory;
import bpmlab.shift.dao.service.GenericDAO;
import bpmlab.shift.entity.Item;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author Mikael Lima
 */
@ManagedBean
@RequestScoped
public class ItemBean implements Serializable {

    private final GenericDAO<Item> dao = DAOFactory.criarGenericDAO(Item.class);
    private Item item = new Item();
    private List<Item> itens;

    public String salvar() {
        try {
            dao.salvar(item);
            JsfUtil.mensagemSalvoComSucesso();
            return "/admin/cardapio/item/lista-item.xhtml";
        } catch (DAOException ex) {
            JsfUtil.mensagemErroAoSalvar();
            return null;
        }
    }

    public void excluir() {
        try {
            dao.excluir(item);
            JsfUtil.mensagemRemovidoComSucesso();
        } catch (DAOException ex) {
            JsfUtil.mensagemErroAoRemover();
        }
    }
    
    public Item getItem() {
        return item;
    }

    public void setItem(Item item) {
        this.item = item;
    }

    public List<Item> getItens() {
        itens = dao.obterTodos();
        return itens;
    }
    
}
